// 引入下载好的路由
import { createWebHashHistory, createRouter } from 'vue-router'
import Home from './views/Home.vue'
import Doc from './views/Doc.vue'
import SwitchDemo from './components/SwitchDemo.vue'
import ButtonDemo from './components/ButtonDemo.vue'
import DialogDemo from './components/DialogDemo.vue'
import TabsDemo from './components/TabsDemo.vue'
import { h } from 'vue'
import Markdown from './components/Markdown.vue'
import intro from './markdown/intro.md'
import getStarted from './markdown/get-started.md'
import install from './markdown/install.md'
// 导入路由中的2个方法， history . router
const history = createWebHashHistory()
const md = (string) => h(Markdown, { content: string, key: string })
export const router = createRouter({
  history: history,
  // 当用户访问的是根路径，渲染Frank组件
  routes: [
    { path: '', component: Home },
    {
      path: '/doc',
      component: Doc,
      children: [
        { path: '', redirect: '/doc/intro' },
        {
          path: 'Intro',
          component: md(intro),
        },
        {
          path: 'get-started',
          component: md(getStarted),
        },
        {
          path: 'install',
          component: md(install),
        },
        { path: 'switch', component: SwitchDemo },
        { path: 'button', component: ButtonDemo },
        { path: 'dialog', component: DialogDemo },
        { path: 'tabs', component: TabsDemo },
      ],
    },
  ],
})
router.afterEach(() => {
  // console.log('路由切换了')
})
